# -*- coding: iso-8859-15 -*-

#    SuperClipboard is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os

class Config:
    
    def __init__(self,copier):
        self.copier= copier
        if self.iswindows():
            #windows
            user_home_path = os.getenv("APPDATA")
            self.path={
                 'Home' : user_home_path,
                 'Conf' : user_home_path+'\superclipboard\config',
                 'StaticConf' : user_home_path+'\superclipboard\staticcopy',
                 'Network' : user_home_path+'\superclipboard\network',
                 'Ico' : '.\img\ico.png'
             }
        else:
            #GNU/Linux
            user_home_path = os.getenv("HOME")
            self.path={
                 'Home' : user_home_path,
                 'Conf' : user_home_path+'/.superclipboard/config',
                 'StaticConf' : user_home_path+'/.superclipboard/staticcopy',
                 'Network' : user_home_path+'/.superclipboard/network',
                 'Ico' : './img/ico.png'
             }
        
        self.conf={
          'Number' : 9,
          'Timer' : 2000,
          'InverseClick' : False,
         }
        
        self.network={
           'ServerEnabled' : False,
           'ServerPort' : 34067,
           'ServerPassword' : 'password',
           'Client' : []
        }
        
        self.staticconf={
            'Version': '3.1.1'
        }
        
        self.staticcopy=[]
       
    def iswindows(self):
        if os.name == 'nt':
            return True
        else:
            return False   
        
    def getstatic(self,i):
        return self.staticconf[i]
    
    def setstatic(self,i,value):
        self.staticconf[i]=value
    
    def get(self,key):
        return self.conf[key]
    
    def set(self,key,value):
        if key == 'Number':
            if value < self.conf['Number']:
                i = self.conf['Number']
                while i > value:
                    self.copier.rm_element(i)
                    i-=1
            self.conf[key] =  value
        else:
            self.conf[key] = value
            
    def getNetworkClients(self):
        return self.network['Client']    